$(function () {
    //节流阀
    var flag = false;
    var pageNum = 1;
    var pullmaster = new Pull($('.activityItemBox'), {
        onPullUp: function () {
            pageNum = 1;
            loadActivity(pageNum);
        },
        onPullDown: function () {
            loadActivity(pageNum);
        }
    });
    function loadActivity(pageNum) {
        if (flag) return false;
        $.ajax({
            // url: domain.test + "/getactivity",
            url: domain.online + "/api/activity/list",
            type: 'get',
            data: "pageNum=" + pageNum,
            dataType: 'json',
            beforeSend: function () {
                flag = true;
            },
            success: function (response) {
                // if (response.data.rtnCode === 200) {
                if(response.rtnCode===200){
                    // var activityDetail = response.data.data;
                    var activityDetail = response.data;
                    if (pageNum === 1) {
                        $('.activityItemBox').html(template('activityItemBox', { activityDetail: activityDetail }));
                    } else {
                        $('.activityItemBox').append(template('activityItemBox', { activityDetail: activityDetail }));
                    }
                    pullmaster.pullDownSuccess();       //刷新成功
                    if (activityDetail.list.length < 10 || activityDetail.list.length === 0) {
                        pullmaster.pullUpDone();
                        $(".bb_pull-up").css({ "display": "none" });
                        $(".end").css({ "display": "block" });
                    }
                    ++pageNum;
                    flag = false;
                }
            },
            error: function () {
                pullmaster.pullDownFailed();        //刷新失败
                pullmaster.pullUpFailed();          //数据加载失败
            }
        })
    }
    //倒计时
    // if(window.cutSecond&&window.cutSecond>1000){
    //     var timer = setInterval(function () {
    //         cutSecond -= 1000;
    //         if (cutSecond === 0) {
    //             clearInterval(timer);
    //             $(".activityTime_c3").html("活动已结束");
    //         }
    //         var hour = Math.floor(cutSecond / 1000 / 3600);
    //         var minute = Math.floor(cutSecond / 1000 / 60 % 60);
    //         var second = Math.floor(cutSecond / 1000 % 60);
    //         hour = hour >= 10 ? hour : "0" + hour;
    //         minute = minute >= 10 ? minute : "0" + minute;
    //         second = second >= 10 ? second : "0" + second;
    //         $(".hour").html(hour);
    //         $(".minute").html(minute);
    //         $(".second").html(second);
    //     }, 1000);
    // }
    //活动详情
    $(".activityItemBox").on("click", ".activityItem", function () {
        var id = $(this).attr("data-id");
        location.href = "./activityDetail.html?id=" + id;
    })
})